//将腾讯、高德地图经纬度转换为百度地图经纬度
function mapPointTxTurnBaiDu (dataLon, dataLat) {
	 let bd_lat;
	 let bd_lon;
	 let x_pi = 3.14159265358979324;
	 let x = dataLon, y = dataLat;
	 let z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
	 let theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
	 bd_lon = z * Math.cos(theta) + 0.0065;
	 bd_lat = z * Math.sin(theta) + 0.006;
	 return { bd_lat, bd_lon };
}
function selectAreaTreeValBaiDu (val) {
  let self = this
  self.houseLists.forEach(item => {
    const pointData = this.mapPointTxTurnBaiDu(item.lng, item.lat)
    item.lng = pointData.bd_lon
    item.lat = pointData.bd_lat
    let point = new self.BMap.Point(item.lng, item.lat)
    let marker = new self.BMap.Marker(point) // 创建标注
    self.map.addOverlay(marker)
  })
}
//百度地图坐标转腾讯、高德地图坐标
function transPosition(bd_lng, bd_lat) {
     var X_PI = Math.PI * 3000.0 / 180.0;
     var x = bd_lng - 0.0065;
     var y = bd_lat - 0.006;
     var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI);
     var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * X_PI);
     var gg_lng = z * Math.cos(theta);
     var gg_lat = z * Math.sin(theta);
     return {lon: gg_lng, lat: gg_lat}
 }
function selectAreaTreeVal (val) {
  let self = this
  self.houseLists.forEach(item => {
    const pointData = this.transPosition(item.lng, item.lat)
    item.lng = pointData.gg_lng
    item.lat = pointData.gg_lat
    let point = new self.AMap.Point(item.lng, item.lat)
    let marker = new self.AMap.Marker(point) // 创建标注
    self.map.addOverlay(marker)
  })
}

// wgs84转火星坐标
function wgs84togcj02(lng, lat) {
	var x_PI = 3.14159265358979324 * 3000.0 / 180.0;
	var PI = 3.1415926535897932384626;
	var a = 6378245.0;
	var ee = 0.00669342162296594323;
	if ((lng < 72.004 || lng > 137.8347) || ((lat < 0.8293 || lat > 55.8271) || false)) {
		return [lng, lat]
	} else {
		var dlat = ((lng, lat) => {
		var ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
		ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
		ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
		ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
		return ret
	})(lng - 105.0, lat - 35.0);
		var dlng = ((lng, lat) => {
		var ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
		ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
		ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
		ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
		return ret
	}
	)(lng - 105.0, lat - 35.0);
		var radlat = lat / 180.0 * PI;
		var magic = Math.sin(radlat);
		magic = 1 - ee * magic * magic;
		var sqrtmagic = Math.sqrt(magic);
		dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
		dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
		var mglat = lat + dlat;
		var mglng = lng + dlng;
		return [mglng, mglat]
	}
}

export default{
	mapPointTxTurnBaiDu,
	selectAreaTreeValBaiDu,
	transPosition,
	selectAreaTreeVal,
	wgs84togcj02
}